package com.appcheck.recording.listener.impl;

import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;

import com.appcheck.recording.ListenerManager;
import com.appcheck.recording.WidgetHelper;
import com.appcheck.recording.action.impl.TimeChangedAction;
import com.appcheck.recording.listener.AbstractListener;

public class TimeChangedListener extends AbstractListener implements
		OnTimeChangedListener {

	private int b;
	
	public TimeChangedListener(TimePicker paramTimePicker) {
		super(paramTimePicker, TimePicker.class, TimePicker.OnTimeChangedListener.class);
	}

	@Override
	public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
	    if (this.b++ > 1) {
	        return;
	     }
	    TimeChangedAction timeChangedAction = new TimeChangedAction();
	    timeChangedAction.setHourOfDay(hourOfDay);
	    timeChangedAction.setMinute(minute);
	    timeChangedAction.setResourceName(WidgetHelper.getResourceName(view));
	    timeChangedAction.setResourceId(WidgetHelper.getResourceId(view));
	    if (timeChangedAction.getResourceName() == null) {
	    	timeChangedAction.setIndex(WidgetHelper.getCurrentIndexOfView(view));
	    }
	    ListenerManager.getListenerManager().handleAction(timeChangedAction);
	    if (this.listener != null) {
	    	((TimePicker.OnTimeChangedListener)this.listener).onTimeChanged(view, hourOfDay, minute);
	    }
	    this.b = 0;
	}

}
